package com.localjoycommunity.cpdj.project.system.controller;

import com.localjoycommunity.cpdj.common.utils.poi.ExcelUtil;
import com.localjoycommunity.cpdj.framework.aspectj.lang.annotation.Log;
import com.localjoycommunity.cpdj.framework.aspectj.lang.enums.BusinessType;
import com.localjoycommunity.cpdj.framework.web.controller.BaseController;
import com.localjoycommunity.cpdj.framework.web.domain.AjaxResult;
import com.localjoycommunity.cpdj.framework.web.page.TableDataInfo;
import com.localjoycommunity.cpdj.project.system.domain.SysMap;
import com.localjoycommunity.cpdj.project.system.service.ISysMapService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 地图Controller
 *
 * @author aqie
 * @date 2020-11-02
 */
@RestController
@RequestMapping("/system/map")
public class SysMapController extends BaseController {
    @Autowired
    private ISysMapService sysMapService;

    /**
     * 查询地图列表
     */
    @GetMapping("/list")
    public TableDataInfo list(SysMap sysMap) {
        startPage();
        List<SysMap> list = sysMapService.selectSysMapList(sysMap);
        return getDataTable(list);
    }

    /**
     * 导出地图列表
     */
    @Log(title = "地图", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(SysMap sysMap) {
        List<SysMap> list = sysMapService.selectSysMapList(sysMap);
        ExcelUtil<SysMap> util = new ExcelUtil<SysMap>(SysMap.class);
        return util.exportExcel(list, "map");
    }

    /**
     * 获取地图详细信息
     */
    @GetMapping(value = "/{mapId}")
    public AjaxResult getInfo(@PathVariable("mapId") Long mapId) {
        return AjaxResult.success(sysMapService.selectSysMapById(mapId));
    }

    /**
     * 新增地图
     */
    @Log(title = "地图", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody SysMap sysMap) {
        return toAjax(sysMapService.insertSysMap(sysMap));
    }

    /**
     * 修改地图
     */
    @Log(title = "地图", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody SysMap sysMap) {
        return toAjax(sysMapService.updateSysMap(sysMap));
    }

    /**
     * 删除地图
     */
    @Log(title = "地图", businessType = BusinessType.DELETE)
    @DeleteMapping("/{mapIds}")
    public AjaxResult remove(@PathVariable Long[] mapIds) {
        return toAjax(sysMapService.deleteSysMapByIds(mapIds));
    }
}
